package hxy.scan.server.controller;

import hxy.scan.server.dao.mapper.TeacherMapper;
import hxy.scan.server.dao.model.TeacherModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
public class TeacherController {


    @Resource
    TeacherMapper teacherMapper;


    @GetMapping("teacher-statistics")
    public Long statisticsTeacherNumber() {

        Long integer = teacherMapper.selectCount(null);
        return integer;
    }


    @GetMapping("teacher-get-by-name")
    public String getByName(String name) {
        log.info("前端传过来的参数是{}", name);
        return "成功";
    }


    @GetMapping("/teacher-create")
    public int create(TeacherModel teacherEntity) {

        String name = teacherEntity.getName();

        if (name == null) {
            return 0;
        }

        // 表示影响行数
        int insert = teacherMapper.insert(teacherEntity);


        return insert;
    }


    /**
     * 光刻机列表查询
     *
     * @return
     */
    @GetMapping("/teacher-list")
    public List<TeacherModel> list() {

        List<TeacherModel> teacherModels = teacherMapper.selectList(null);

        return teacherModels;
    }

    @GetMapping("/teacher-delete")
    public int delete(int name) {
        return teacherMapper.deleteById(name);
    }

    @GetMapping("/teacher-update")
    public int update(TeacherModel customerEntity) {

        return teacherMapper.updateById(customerEntity);
    }
}